﻿Imports HMSDataLayer
Imports HMSLibrary

Public Class LookupsWindow

    Dim _FormType As LookupsList

    Private Sub LookupSearchBox_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Input.KeyEventArgs) Handles LookupSearchBox.KeyDown
        If _FormType = LookupsList.ItemsServicesList Then
            Dim lst As List(Of ItemsService)
            lst = Me.DataContext
            Dim obj = (From item In lst Where item.Name.ToLower.Contains(LookupSearchBox.Text.ToLower) Order By item.Name Select item).ToList
            LookupsListBox.ItemsSource = obj
        ElseIf _FormType = LookupsList.ComplaintsList Then
            Dim lst As List(Of Complaints)
            lst = Me.DataContext
            Dim obj = (From item In lst Where item.Name.ToLower.Contains(LookupSearchBox.Text.ToLower) Order By item.Name Select item).ToList
            LookupsListBox.ItemsSource = obj
        Else
            Dim lst As List(Of Lookups)
            lst = Me.DataContext
            Dim obj = (From item In lst Where item.Name.ToLower.Contains(LookupSearchBox.Text.ToLower) Order By item.Name Select item).ToList
            LookupsListBox.ItemsSource = obj
        End If
    End Sub

    Private Sub LookupsWindow_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        Dim dataProvider As New MasterDataLayer()
        If _FormType = LookupsList.UOMList Then
            Dim lst As List(Of Lookups)
            Me.DataContext = dataProvider.GetLookupList(LookupTypes.UOM)
            lst = Me.DataContext
            LookupsListBox.ItemsSource = lst
        ElseIf _FormType = LookupsList.InventoryItemsList Then
            Dim lstItem As List(Of ItemsService)
            Me.DataContext = dataProvider.GetItemList()
            lstItem = Me.DataContext
            LookupsListBox.ItemsSource = lstItem
        ElseIf _FormType = LookupsList.ItemsServicesList Then
            Dim lstItem As List(Of ItemsService)
            Me.DataContext = dataProvider.GetItemServiceList()
            lstItem = Me.DataContext
            LookupsListBox.ItemsSource = lstItem
        ElseIf _FormType = LookupsList.BillCharges Then
            Dim lst As List(Of Lookups)
            Me.DataContext = dataProvider.GetLookupList(LookupTypes.BillCharges)
            lst = Me.DataContext
            LookupsListBox.ItemsSource = lst
        ElseIf _FormType = LookupsList.ComplaintsList Then
            Dim lst As List(Of Complaints)
            Me.DataContext = dataProvider.GetComplaintsList()
            lst = Me.DataContext
            LookupsListBox.ItemsSource = lst
        End If
    End Sub

    Public Sub New(ByVal FormType As LookupsList)

        _FormType = FormType
        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
    End Sub

    Private Sub LookupsListBox_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles LookupsListBox.MouseDoubleClick
        If LookupsListBox.SelectedItem Is Nothing Then Exit Sub
        SelectedObject = LookupsListBox.SelectedItem
        Me.Close()
    End Sub

    Public Property SelectedObject As Object

    Private Sub LookupsWindow_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles Me.MouseDown
        DragMove()
    End Sub

    Private Sub CloseButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles CloseButton.Click
        Me.Close()
    End Sub

    Private Sub MinimizeButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles MinimizeButton.Click
        Me.WindowState = Windows.WindowState.Minimized
    End Sub
End Class
